#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<pair<int,int>> v;
void cal(int x,int y,int n,int m){
    if(n==m){
        for(int i=1;i<=n;++i){
            v.emplace_back(x+i,y+1);
        }
        for(int i=2;i<n;++i){
            v.emplace_back(x+i,y+n);
        }
        return;
    }
    if(n<m){
        for(int i=1;i<=n;++i)v.emplace_back(x+i,y+1);
        cal(x,y+n,n,m-n);
    }
    else{
        for(int i=1;i<=m;++i)v.emplace_back(x+1,y+i);
        cal(x+m,y,n-m,m);
    }
}
int main(){
    freopen("bishop.in","r",stdin);
    freopen("bishop.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    cal(0,0,n,m);
    cout<<v.size()<<'\n';
    for(auto it:v)cout<<it.first<<' '<<it.second<<'\n';
    return 0;
}
